package com.applet.config;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.applet.entity.ApplicationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * Created by Administrator on 2017/10/27.
 */
@Configuration
public class MQConfig {

    @Autowired
    private ApplicationProperties appProperties;

    @Bean
    public Producer mqStart(){
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.ProducerId, appProperties.getProduceIdGov());
        properties.put(PropertyKeyConst.AccessKey, appProperties.getAk());
        properties.put(PropertyKeyConst.SecretKey, appProperties.getSk());
        properties.put(PropertyKeyConst.ONSAddr, appProperties.getMqAddress());
        Producer producer = ONSFactory.createProducer(properties);
        producer.start();
        return producer;
        // 在发送消息前，必须调用 start 方法来启动 Producer，只需调用一次即可
    }



}
